package ONLINE_EXAM;

public class tx_2 {

    public int[] findBuilding (int[] heights) {
        int[] hres = new int[heights.length];
        for (int i= 0;i<heights.length;i++){
            hres[i] = heightres(i,heights);
        }
        return hres;

        // write code here
    }
    public int heightres(int position,int[] heights){
        int res =0;
        if (position ==0 || position==heights.length-1){
            res = 2;
        }else {
            res = 3;
        }


        if (position< heights.length-1){
            int max_right = position+1;
            int maxr = heights[max_right];
            while (++max_right <heights.length){
                if (heights[max_right] > maxr){
                    res++;
                    maxr = heights[max_right];
                }
            }
        }
        if (position >= 0){
            int max_left = position-1;
            int maxl = heights[max_left];
            while (--max_left > 0){
                if (heights[max_left] > maxl){
                    res++;
                    maxl = heights[max_left];
                }

            }
        }

        return res;


    }
}
